home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ABUSESRC.ZIP / AbuseSrc / macabuse / imlib / mouse.c < prev    next >
C/C++ Source or Header  |  1997-05-20  |  2KB  |  111 lines

  1. #include "video.hpp"
  2. #include "sprite.hpp"
  3. #include "image.hpp"
  4. #include "filter.hpp"
  5. #include "mdlread.hpp"
  6. #include "monoprnt.hpp"
  7. #include "mouse.hpp"
  8.  
  9. unsigned char def_mouse[]=
  10.     { 0,2,0,0,0,0,0,0,
  11.       2,1,2,0,0,0,0,0,
  12.       2,1,1,2,0,0,0,0,
  13.       2,1,1,1,2,0,0,0,
  14.       2,1,1,1,1,2,0,0,
  15.       2,1,1,1,1,1,2,0,
  16.       0,2,1,1,2,2,0,0,
  17.       0,0,2,1,1,2,0,0,
  18.       0,0,2,1,1,2,0,0,
  19.       0,0,0,2,2,0,0,0 };    // 8x10
  20.  
  21. int Mbut,Mx,My;
  22.  
  23.  
  24.  
  25. void JCmouse::set_shape(image *im, int centerx=0, int centery=0)
  26. {
  27.   sp->change_visual(im,1);
  28.   cx=-centerx;
  29.   cy=-centery;
  30. }
  31.  
  32.  
  33.  
  34. JCMouse::JCMouse(image *Screen, palette *pal)
  35. {
  36.   image *im;
  37.   int br,dr,h;
  38.   filter f;
  39.   but=0;
  40.   cx=cy=0;
  41. #ifdef __DOS
  42.   asm {
  43.     mov ax, 0             // detect the mouse
  44.     int 0x33
  45.     mov h, ax
  46.   }
  47.   here=h;
  48. #else 
  49.   here=1;
  50. #endif
  51.   if (here)                     // is it here?
  52.   {
  53.     screen=Screen;
  54.     br=pal->brightest(1);
  55.     dr=pal->darkest(1);
  56.     f.set(1,br);
  57.     f.set(2,dr);
  58.     im=new image(8,10,def_mouse);
  59.     f.apply(im);
  60.     sp=new sprite(Screen,im,100,100);
  61. #ifdef __DOS
  62.     asm {                // mouse the mouse pointer to 40,40
  63.       mov ax, 4
  64.       mov cx, 40
  65.       mov dx, 40
  66.       int 0x33
  67.     }
  68. #endif
  69.   }
  70. }
  71.  
  72. void JCMouse::update(int newx, int newy, int new_but)
  73. {
  74.   int butn,xx,yy;
  75.   if (newx<0)
  76.   {
  77. #ifdef __DOS
  78.     if (here)
  79.     {
  80.       asm {
  81.         mov ax, 0x0b
  82.         int 0x33            // get the mouse movement
  83.         mov xx,cx
  84.         mov yy,dx
  85.         mov ax, 3
  86.         int 0x33           // get the mouse button status
  87.         mov butn,bx
  88.       }
  89.       lx=mx; ly=my; lbut=but;
  90.       but=butn;
  91.       mx+=xx;
  92.       my+=yy;
  93.       if (mx<0) mx=0;
  94.       if (my<0) my=0;
  95.       if (mx>=screen->width()) mx=screen->width()-1;
  96.       if (my>=screen->height()) my=screen->height()-1;
  97.     }
  98. #else
  99.     Window w1,w2;
  100.     int j;
  101.     unsigned int mask;
  102.     lx=mx; ly=my; lbut=but;
  103.     XQueryPointer(display,mainwin,&w1,&w2,&j,&j,&mx,&my,&mask);
  104.     but=((mask&Button1Mask)!=0)|
  105.          ((mask&Button2Mask)!=0)<<2|
  106.          ((mask&Button3Mask)!=0)<<1;
  107. #endif
  108.   } else 
  109.   { mx=newx; my=newy; but=new_but; }
  110. }
  111.